#include <bits/stdc++.h>
using namespace std;
const int MAXN=1e6+50;
int N,K,Q;
int a[MAXN];
int sta[MAXN],Top;
int ls[MAXN],rs[MAXN];
long long Solve(int Id)
{
	long long ans=0,Now=a[Id];
	int Nowl=Id,Nowr=Id;
	for(int i=1;i<N;i++)
	{
		if(Nowl!=1&&a[Nowl-1]<=Now)
		{
			Nowl--;
			ans++;
		}
		else
		{
			if(Nowr!=N&&a[Nowr+1]<=Now)
			{
				Nowr++;
				ans++;
			}
			else
			{
				if(a[Nowl-1]<=a[Nowr+1])
				{
					
					ans+=1+K;
					Now=a[Nowl-1];
					Nowl--;
				}
				else
				{
					
					ans+=1+K;
					Now=a[Nowr+1];
					Nowr++;
				}
			}
		}
	}
	return ans;
}

int main()
{
	freopen("summer.in","r",stdin);
	freopen("summer.out","w",stdout);
	a[0]=a[N+1]=1e9+1;
	scanf("%d%d",&N,&K);
	for(int i=1;i<=N;i++)
	{
		scanf("%d",&a[i]);
	}
	scanf("%d",&Q);
	while(Q--)
	{
		int x,l,r;
		scanf("%d%d%d",&x,&l,&r);
		swap(a[x],a[x+1]);

		long long ans=0;
		for(int i=l;i<=r;i++)
		{

			ans+=Solve(i);
		}
		printf("%lld\n",ans);
	}
}

